package com.chixing.day04_oop.word;

public class CreditAccount extends Account{
    private float maxOverdraw;      // 最高透支额度
    private float alreadyOverdraw; // 已经透支的额度

    private int credit;

    public float getMaxOverdraw() {
        return maxOverdraw;
    }

    public void setMaxOverdraw(float maxOverdraw) {
        this.maxOverdraw = maxOverdraw;
    }

    public float getAlreadyOverdraw() {
        return alreadyOverdraw;
    }

    public void setAlreadyOverdraw(float alreadyOverdraw) {
        this.alreadyOverdraw = alreadyOverdraw;
    }

    public int getCredit() {
        return credit;
    }

    public void setCredit(int credit) {
        this.credit = credit;
    }

    public void overdraw(float n){
        if (super.accBalance>=n){
            super.accBalance -=n;
        }
        else{
            this.alreadyOverdraw = n -super.accBalance + this.alreadyOverdraw;
            super.accBalance = 0;
        }
    }

    @Override
    public String toString() {
        return "CreditAccount{" +
                "maxOverdraw=" + maxOverdraw +
                ", alreadyOverdraw=" + alreadyOverdraw +
                ", credit=" + credit +
                ", accBalance=" + accBalance +
                '}';
    }
}
